package controller

import (
	"fx_swift_ifcgate/api"
	"fx_swift_ifcgate/internal/service"
	"fx_swift_ifcgate/pkg/code"
	"fx_swift_ifcgate/pkg/internalerrors"
	"fx_swift_ifcgate/pkg/validator"
	"github.com/gin-gonic/gin"
	"net/http"
)

func OttPayTp1002(c *gin.Context) {
	req := &api.Tp1002Req{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, validator.GetErrorMsg(req, err))
		return
	}
	result, err := service.NewExchangeCurrencySrv().OttPayTp1002(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

func OttPayTp3004(c *gin.Context) {
	result, err := service.NewExchangeCurrencySrv().OttPayTp3004(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}

func OttPayTp1003(c *gin.Context) {
	quoteId := c.Query("quoteId")
	err := service.NewExchangeCurrencySrv().OttPayTp1003(c, quoteId)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

func ExchangeCurrencyList(c *gin.Context) {
	req := &api.ExchangeCurrencyListReq{}
	if err := c.ShouldBindJSON(&req); err != nil {
		code.Fail(c, http.StatusBadRequest, code.ErrEncodingJSON, err.Error())
		return
	}
	result, err := service.NewExchangeCurrencySrv().ExchangeCurrencyList(c, req)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, result)
	}
}
